package com.frxuexi.repair

import com.blankj.utilcode.util.SPUtils
import com.frxuexi.lib_base.http.ApiService
import com.frxuexi.lib_base.http.Const
import com.frxuexi.lib_base.http.RequestType
import com.frxuexi.lib_base.mvi.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class RepairViewModel @Inject constructor(val apiService: ApiService):BaseViewModel<RepairIntent>(){
    override fun handleIntent(it: RepairIntent) {
        when(it){
            is RepairIntent.getRepairs->httpRequest(apiService.getRepairs())
            is RepairIntent.getRepairByNum->httpRequest(apiService.getRepairByNum(it.num),RequestType.SELECT_ITEM)
            is RepairIntent.getRepairsByUname->httpRequest(apiService.getRepairsByUname(it.uname),RequestType.SELECT_KEY)
            is RepairIntent.deleteRepair->httpRequest(apiService.deleteRepair(it.id),RequestType.DELETE)
            is RepairIntent.getLocs->httpRequest(apiService.getKeys(),RequestType.SELECT_KEY)
            is RepairIntent.upload->httpRequest(apiService.upload(toMultiBody(it.name,it.path).parts,"repair",SPUtils.getInstance().getInt(Const.UID,-1).toString()),RequestType.UPLOAD)
            is RepairIntent.addRepair->httpRequest(apiService.addRepair(toBody(it.item)),RequestType.ADD)
            is RepairIntent.getRepairById->httpRequest(apiService.getRepairById(it.id),RequestType.SELECT_ITEM)
            is RepairIntent.updateRepair->httpRequest(apiService.updateRepair(it.id,toBody(it.item)),RequestType.UPDATE)
        }
    }
}